﻿using Core;
using System;
using System.Reflection;
using UnityEngine;

public class Entry
{
    public static async void Start()
    {
        World.AddComponent<CodeTypes, Assembly[]>(new Assembly[] { typeof(Entry).Assembly, typeof(Player).Assembly });
        World.AddComponent<ResourceComponent>();
        World.AddComponent<FGUIComponent>();
        World.AddComponent<EventComponent>();
        World.AddComponent<TimerComponent>();
        World.AddComponent<ConfigComponent>();
        World.AddComponent<EffectComponent>();
        World.AddComponent<BulletComponent>();
        World.AddComponent<InputComponent>();
        World.AddComponent<SceneItemMgr>();
        World.AddComponent<NavMeshComponent>();
        World.AddComponent<LangComponent>();
        World.AddComponent<RandomSkillComponent>();
        World.AddComponent<SkillTriggerComponent>();
        World.AddComponent<NumericWatcherComponent>();

        World.GetComponent<ResourceComponent>().LoadAssetBundleAsync("common", true).Coroutine();

        var unitComponent = World.AddComponent<UnitComponent>();
        var player = await unitComponent.CreateAsync(World.Main.Root, 1);
        player.AddComponent<Player>();

        //var geyser = await unitComponent.CreateAsync(World.Main.Root, 3);
        //geyser.Position = Vector3.back ;

        var loader = World.GetComponent<ConfigComponent>().GetLoader<MapLevelConfigLoader>();
        var config = loader.GetConfig(0, 1);
        var unit = await EnemyHelper.Create(config);
        unit.Position = Vector3.forward * 1;

        await World.GetComponent<FGUIComponent>().ShowWindow<MainWindow>();

        //World.GetComponent<FGUIComponent>().ShowWindow<InventoryWindow>().Coroutine();
        //var window = await World.GetComponent<FGUIComponent>().ShowWindow<RoleInfoWindow>();
        //window.Bind(player);
    }
}

